home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / mui / mui-tools / multiuser / src / support / runcommand.c < prev    next >
C/C++ Source or Header  |  1995-03-09  |  2KB  |  83 lines

  1. /************************************************************
  2. * MultiUser - MultiUser Task/File Support System                *
  3. * ---------------------------------------------------------    *
  4. * RunCommand - Run a Pogram using the Current Process            *
  5. * ---------------------------------------------------------    *
  6. * © Copyright 1993-1994 Geert Uytterhoeven                        *
  7. * All Rights Reserved.                                                    *
  8. ************************************************************/
  9.  
  10.  
  11. #include <exec/types.h>
  12. #include <exec/memory.h>
  13. #include <exec/execbase.h>
  14. #include <dos/dos.h>
  15. #include <proto/exec.h>
  16. #include <proto/dos.h>
  17. #include "string.h"
  18.  
  19. #include "RunCommand_rev.h"
  20.  
  21. #include "Locale.h"
  22.  
  23. char __VersTag__[] = VERSTAG;
  24.  
  25.  
  26. int __saveds Start(char *arg)
  27. {
  28.     struct ExecBase *SysBase;
  29.     struct DosLibrary *DOSBase;
  30.     struct RDArgs *args;
  31.     LONG argarray[] = {
  32. #define argCOMMAND    0
  33. #define argARGS        1
  34.         NULL, NULL
  35.     };
  36.     int rc = RETURN_ERROR;
  37.     BPTR seglist;
  38.     ULONG stacksize;
  39.     STRPTR argptr;
  40.     ULONG argsize;
  41.     struct Process *proc;
  42.     struct CommandLineInterface *cli;
  43.  
  44.     SysBase = *(struct ExecBase **)4;
  45.  
  46.     if (!(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37))) {
  47.         rc = ERROR_INVALID_RESIDENT_LIBRARY;
  48.         goto Exit;
  49.     }
  50.  
  51.     args = ReadArgs("COMMAND/A,ARGS/F", argarray, NULL);
  52.     if (!args || (!(seglist = NewLoadSeg((STRPTR)argarray[argCOMMAND], NULL))))
  53.         PrintFault(IoErr(), NULL);
  54.     else {
  55.         proc = (struct Process *)SysBase->ThisTask;
  56.         if (cli = (struct CommandLineInterface *)BADDR(proc->pr_CLI)) {
  57.             stacksize = cli->cli_DefaultStack*4;
  58.             if (argarray[argARGS]) {
  59.                 argsize = strlen((char *)argarray[argARGS])+1;
  60.                 if (argptr = AllocVec(argsize+1, MEMF_PUBLIC|MEMF_CLEAR)) {
  61.                     strcpy(argptr, (char *)argarray[argARGS]);
  62.                     strcat(argptr, "\n");
  63.                     rc = RunCommand(seglist, stacksize, argptr, argsize);
  64.                     FreeVec(argptr);
  65.                 } else
  66.                         PrintFault(IoErr(), NULL);
  67.             } else
  68.                 rc = RunCommand(seglist, stacksize, "\n", 1);
  69.             if (rc == -1) {
  70.                 rc = RETURN_FAIL;
  71.                 PutStr(GetLocStr(MSG_NOMEMSTACK));
  72.             }
  73.             UnLoadSeg(seglist);
  74.         } else
  75.             PutStr(GetLocStr(MSG_ONLYFROMCLI));
  76.     }
  77.  
  78. Exit:
  79.     CloseLibrary((struct Library *)DOSBase);
  80.  
  81.     return(rc);
  82. }
  83.